<?php
class neighborhooddao extends CI_Model{
	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}

	public function insert($neighborhood_name,$postal_code,$district_id){
		$data = array(
				'neighborhood_name' => $neighborhood_name,
				'postal_code' => $postal_code,
				'district_id' => $district_id
		);
		$str = $this->db->insert_string('neighborhood', $data);
		$res = $this->db->query($str);
		if (!$res) {
			return false;
		} else {
			return true;
		}
	}

	public function del($neighborhood_id) {
			$this->db->where('neighborhood_id', $neighborhood_id);
			$this->db->delete('neighborhood');
			return ($this->db->affected_rows() == 1) ? TRUE : FALSE;
	}

	public function getbyid($neighborhood_id){
		$this->db->select('*');
		$this->db->from('neighborhood');
		$this->db->where('neighborhood_id',$neighborhood_id);
		$query = $this->db->get();
		$neighborhood = $query->row();
		return $neighborhood;
	}

	public function get_all(){
		$this->db->select('*');
		$this->db->from('neighborhood');
		$query = $this->db->get();
		$neighborhoods = $query->result();
		return $neighborhoods;
	}
	
	function get_by_district($district_id){
		$this->db->select('neighborhood.*');
		$this->db->from('district');
		$this->db->join('neighborhood', 'district.district_id
					 = neighborhood.district_id');
		$this->db->where('neighborhood.district_id',
				$district_id);
		$query = $this->db->get();
		$result = $query->result();
		return $result;
	}

}
